<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="com.shsh.safemanage.model.JobPost"%>
<%@page import="com.shsh.safemanage.dao.TitlePostManageGroupDao"%>
<%@page import="java.util.Calendar"%>
<%@page import="com.shsh.safemanage.dao.DepartmentDao"%>
<%@page import="com.shsh.safemanage.model.Department1"%>
<%@page import="com.shsh.safemanage.model.ProblemTransfer"%>
<%@page import="java.util.List"%>
<%@page import="com.shsh.safemanage.util.Util"%>
<%@page import="com.shsh.safemanage.model.Problem"%>
<%@page import="com.shsh.safemanage.dao.DaoCreator"%>
<%@page import="com.shsh.safemanage.dao.ProblemDao"%>
<%@page import="com.shsh.safemanage.util.Constants"%>

<%
session.removeAttribute(Constants.SESSION_MANAGE_GROUP_USER);
session.removeAttribute(Constants.SESSION_PROBLEM_DEPARTMENT1);

String problemIDStr = request.getParameter(Constants.REQUEST_PARAMETER_ID);
Long problemID = 0L;
try {
	problemID = new Long(problemIDStr);
} catch (Exception e) {
}

String transferIDStr = request.getParameter(Constants.REQUEST_PARAMETER_TRANSFER_ID);
Long transferID = 0L;
try {
	transferID = new Long(transferIDStr);
} catch (Exception e) {
}

DepartmentDao departmentDao = DaoCreator.createDepartmentDao();
ProblemDao problemDao = DaoCreator.createProblemDao();
TitlePostManageGroupDao titlePostManageGroupDao = DaoCreator.createTitlePostManageGroupDao();
WriteProblemAction writeProblemAction = ActionCreator.createWriteProblemAction();

Problem problem = problemDao.getProblemByID(problemID);
User user = (User) session.getAttribute(Constants.SESSION_USER);
JobPost post1 = titlePostManageGroupDao.getJobPostByID(user.getJobPost1ID());
JobPost post2 = titlePostManageGroupDao.getJobPostByID(user.getJobPost2ID());
JobPost post3 = titlePostManageGroupDao.getJobPostByID(user.getJobPost3ID());

int role = writeProblemAction.calRole(post1, post2, post3);
%>
<div class="hider" id="hider">
	<span>&nbsp;</span>
</div>
<div class="position">
	<img src="images/position2.jpg" style="padding: 7px 9px; float: left;" />当前位置：中国石化安全问题管理平台 &gt;&gt; 处理问题
</div>

<div class="tt">问题浏览及反馈卡</div>
<div class="content">
	<%
	if ((role & (Constants.ROLE_TYPE_ZUYUAN | Constants.ROLE_TYPE_KEYUAN)) == 0) {
	%>
	<%@include file="problem_detail_section.jsp"%>
	<%
	}
	%>
	<table align="center" border="1" width="99%" cellpadding="0"
		cellspacing="0">
		<%
		if ((role & (Constants.ROLE_TYPE_ZUYUAN | Constants.ROLE_TYPE_KEYUAN)) > 0) {
		%>
		<tr>
			<td class="td1">
				<span style="margin-left: 30px; font-weight: bold">通报内容标题：</span>
				<%=problem.getProblemTitle()%>
			</td>
		</tr>
		<tr>
			<td class="td1">
				<span style="margin-left: 30px; font-weight: bold">通报内容：</span>
				<br />
				<span style="margin-left: 30px">问题内容：</span>
				<%=problem.getProblemContent()%>
				<br />
				<span style="margin-left: 30px">整改措施：</span>
				<%=problem.getProblemZhenggai()%>
			</td>
		</tr>
		<%
		}
		%>
		<tr>
			<td class="td1">
				<span style="margin-left: 30px; font-weight: bold">反馈信息：</span>
				<br />
				<div id="feedbackProcessMethodDiv">
				<%@include file="feedback_process_method.jsp" %>
				</div>
				<textarea style="width: 600px; height: 100px; margin-left: 60px" id="feedback"></textarea>
			</td>
		</tr>
		<tr id="informedPersonsTR">
			<td class="td1">
				<%
				if ((role & Constants.ROLE_TYPE_ZUZHANG) > 0) {
				%>
				<div id="informPersonDiv">
				<%@include file="problem_feedback_informed_person.jsp" %>
				</div>
				<%
				}
				%>
				<%
				if ((role & (Constants.ROLE_TYPE_ZHUANGZHIZHANG | Constants.ROLE_TYPE_ZUZHANG)) > 0) {
				%>
				<div id="chooseManageGroupUserDiv">
				<%@include file="problem_feedback_managegroup_user.jsp"%>
				</div>
				<%
				}
				%>
				<%
				if ((role & (Constants.ROLE_TYPE_KEYUAN | Constants.ROLE_TYPE_KEZHANG | Constants.ROLE_TYPE_FUKEZHANG 
						| Constants.ROLE_TYPE_FUCHUZHANG | Constants.ROLE_TYPE_CHUZHANG)) > 0) {
				%>
				<div id="chooseChushiTransferDiv">
				<%@include file="chushi_informed_person.jsp"%>
				</div>
				<%
				}
				%>
			</td>
		</tr>
		<tr>
			<td class="td1">
				<span style="margin-left: 30px" class="span1">填报人及时间：</span>
				<span><%=user.getDepartment1Name()%>-<%=user.getDepartment2Name()%>-<%=user.getDepartment3Name()%></span>
				<span><%=user.getName()%></span>
				<span><%=Util.formatDateTime(Calendar.getInstance())%></span>
			</td>
		</tr>
		<tr>
			<td class="td1" align="center">
				<input type="button" value="提 交" onclick="feedback()" />
				<input type="button" value="取 消" style="margin-left: 20px" onclick="cancelFeedback()" />
			</td>
		</tr>
	</table>
</div>

<script type="text/javascript">
function feedback() {
	var feedback = getElementValueByID('feedback');
	if (feedback == '') {
		$.dialog.alert('请输入反馈意见');
		return;
	}
	
	var processMethod = 0;
	var processRadio1 = document.getElementById('processRadio1');
	var processRadio2 = document.getElementById('processRadio2');
	var processRadio3 = document.getElementById('processRadio3');
	var processRadio4 = document.getElementById('processRadio4');
	var processRadio5 = document.getElementById('processRadio5');
	if (processRadio1 != null && processRadio1.checked) {
		processMethod = 1;
	} else if (processRadio2 != null && processRadio2.checked) {
		processMethod = 2;
	} else if (processRadio3 != null && processRadio3.checked) {
		processMethod = 3;
	} else if (processRadio4 != null && processRadio4.checked) {
		processMethod = 4;
	} else if (processRadio5 != null && processRadio5.checked) {
		processMethod = 5;
	}
	
	$.dialog.confirm('您确定反馈此问题？', function() {
		openWaitingDialog('waitingDialog');
		$.ajax({
			type:'post',
			url:'feedback_problem_process.jsp',
			data:{
				processMethod: processMethod,
				id: <%=problemID%>,
				feedback: getElementValueByID('feedback'),
				transferID: <%=transferID%>
			},
			success:function(data,state,xmlhttp){
				var obj = null;
				try {
					obj = eval('(' + data + ')');
				} catch (e) {
				}
				if (typeof(obj.isSuccess) != 'undefined') {
					closeWaitingDialog('waitingDialog');
					if (obj.isSuccess == 'true') {
						$.dialog('问题反馈成功！', function() { loadPageSection('/safe_manage/problems_tobe_processed.jsp', 'mainContentDiv'); });
					} else {
						$.dialog.alert(obj.error);
					}
				}
			}
		});
	});
}

function cancelFeedback() {
	$.dialog.confirm('您确定取消此次反馈吗？', function() {
		loadPageSection('/safe_manage/problems_tobe_processed.jsp', 'mainContentDiv');
	}, function(){});
}

function chooseProcessMethod(method) {
	if (method == 1) {
		document.getElementById('informedPersonsTR').style.display = 'none';
		document.getElementById('feedback').readonly = true;
		setElementValueByID('feedback', '<%=user.getDepartment1Name()%>，<%=user.getJobPost1Name()%><%=user.getName()%>确认该问题已整改');
	} else if (method == 2) {
		document.getElementById('informedPersonsTR').style.display = '';
		document.getElementById('feedback').readonly = false;
		setElementValueByID('feedback', '');
	} else if (method == 4 || method == 3 || method == 5) {
		document.getElementById('informedPersonsTR').style.display = 'none';
		setElementValueByID('feedback', '');
	}
}
</script>
